import numpy as np
import numpy.linalg as npl
import newton_raphson as nr
import Electrostatic_Equilibrium as ee

def singleTest(X, N, epsilon):
    Y=ee.equilibrium(X, N, epsilon)
    return npl.norm(ee.gradientE(Y))<epsilon

def globalTest(N, n, epsilon, nb_of_test): 
#N is the maximal number of iterations used in newton_raphson function 
# n is the size of the generated random vectors in the tests
# epsilon is the epsilon used in newton_raphson function.
    tests_OK=0
    tests_KO=0
    for i in range(0,nb_of_test):
        if (singleTest(ee.randomVect(n), N, epsilon)):
            tests_OK+=1
        else:
            tests_KO+=1
    print "Tests OK : "
    print tests_OK
    print "Tests KO : "
    print tests_KO 

#some example of tests on vectors of size 3:
#globalTest(100, 3, 0.01, 100)
#globalTest(100, 3, 0.00001, 100)

def detailedSingleTest(X, N, epsilon):
    #A more detailed test, printing the equilibrium position found
    print X
    Y=ee.equilibrium(X, N, epsilon)
    print Y
    return npl.norm(ee.gradientE(Y))<epsilon

#X=ee.randomVect(3)
#print detailedSingleTest(X, 100, 0.00001)
